/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.util;

import java.util.concurrent.ThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
public class BaseThreadFactory implements ThreadFactory {

    private static final Logger logger = LoggerFactory.getLogger(BaseThreadFactory.class);
    private ThreadGroup threadGroup;
    private String threadName;
    private int num = 1;

    /**
     *
     * @param threadGroupName
     * @param threadName
     */
    public BaseThreadFactory(String threadGroupName, String threadName) {
        this.threadGroup = new ThreadGroup(threadGroupName);
        this.threadName = threadName;
    }

    /**
     *
     */
    public BaseThreadFactory() {
        this.threadGroup = new ThreadGroup("Default Thread Group");
        this.threadName = "Thread";
    }

    /**
     *
     * @param threadGroup
     */
    public BaseThreadFactory(ThreadGroup threadGroup) {
        this.threadGroup = threadGroup;
        this.threadName = "Thread";
    }

    /**
     *
     * @param threadGroup
     * @param threadName
     */
    public BaseThreadFactory(ThreadGroup threadGroup, String threadName) {
        this.threadGroup = threadGroup;
        this.threadName = threadName;
    }

    @Override
    public Thread newThread(Runnable r) {
        logger.debug("Creating new Thread {} ...", num);
        return new Thread(threadGroup, r, threadName + " " + num++);
    }
}
